<?php
/**
 * @orm tablename upload_images
 */
class UploadImage extends  DomArObject {
	
	/**
	 * @orm plugin DomArImage({autoRename=1r})
	 * @orm listener afterAdd afterAddImage
	 */
	public $icon;
	
	public function afterAddImage() {
		if( $this->icon->exists() ) {
			$this->icon->resize(150,150,false);
			$this->icon->cut(150,150);
		}
		
	}
	
	public static function createSampleData() {
		
		UploadImage::getTable()->update();
		
		$item = UploadImage::query()->limit(1)->commit();
		if( $item )
			return;

		$images = array('1.jpg','2.png','3.jpg','4.png','5.jpg','6.jpg','7.jpg');
		
		for( $i=0; $i<4; $i++ ) {
			$item = new UploadImage();
			//$item->title = 'Image '.($i+1);
			$item->icon->addExisting( DOM_MEDIA_DIR.'ImageGridIcons/'.$images[$i%7] );
			$item->save();
		}

		
	}
	
}
?>